
import { configureStore } from '@reduxjs/toolkit';
import { combineReducers } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage'; // 使用localStorage
import userSlice from './userSlice.ts';
import shopSlice from './shopSlice.ts';
import bedmassage from "./bedMassage";
import drugsManage from './drugsManage'
// 持久化存储配置对象
const persistConfig = {
    key: 'root',
    version: 1,
    storage,
    // 只指定userSlice需要持久化
    whitelist: ['userSlice']
};

// 持久化处理后的reducers
const persistedReducer = persistReducer(
    persistConfig,
    combineReducers({
        userSlice,
        shopSlice,
        bedmassage,
        drugsManage
    })
);

// 创建store
const store = configureStore({
    reducer: persistedReducer,
    middleware: (getDefaultMiddleware) =>
        getDefaultMiddleware({
            serializableCheck: false
        })
});

// 创建persistor
const persistor = persistStore(store);

export { store, persistor };

